package cn.gdrj.est.annotations;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * TODO(这里用一句话描述这个类的作用)
 *
 * @author jun
 * @date 2021/11/15
 */
public class TemporalIntervalTimeSegmentValidator implements ConstraintValidator<TemporalIntervalTimeSegment, Integer> {
    int[] values;

    @Override
    public void initialize(TemporalIntervalTimeSegment constraintAnnotation) {
        this.values = constraintAnnotation.values();
    }

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        if (value == null) {
            return false;
        }
        int intValue = value.intValue();
        for (int val : values) {
            if (val == intValue) {
                return true;
            }
        }
        return false;
    }
}
